import {Component} from '@angular/core';
import {
    AlertController, IonicPage, LoadingController, NavController, NavParams, Platform, ToastController,
    ViewController
} from 'ionic-angular';
import {SystemService} from "../../service/SystemService";
import {BasePage} from "../../BasePage";
import {UserManager} from "../../../framework/manager/UserManager";
import {Log} from "../../../framework/utils/Log";

/**
 * Generated class for the PlanPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
    selector: 'page-plan',
    templateUrl: 'plan.html',
    providers: [SystemService]
})
export class PlanPage extends BasePage {
    private static TAG:string="PlanPage";
    planList: Array<any>= [];
    searchName: string;
    private branchId: string;
    private year: string;
    private userId:string;
    danJuBH:string;
    bxType:string;
    constructor(public navCtrl: NavController, public navParams: NavParams, public view: ViewController, public sys: SystemService, public platform: Platform,
                public loadingCtrl: LoadingController,
                public toastCtrl: ToastController,
                public alertCtrl: AlertController) {
        super(platform, loadingCtrl, toastCtrl, alertCtrl);
        this.branchId = UserManager.getInstance().user.branchId;
        this.year = UserManager.getInstance().user.year;
        this.userId = UserManager.getInstance().user.userId;
        this.planList = navParams.data.list;
        this.danJuBH = navParams.data.danJuBH;
        this.bxType = navParams.data.bxType;
    }

    ionViewDidLoad() {
        Log.w(PlanPage.TAG,"ionViewDidLoad");
    }

    selectHandler(item) {
        let newItem = {
            name: item.zhiBiaoMC,
            fee: item.keYongYE,
            zbid: item.bianHao
        };
        this.view.dismiss(newItem);
    }

    //获取指标
    getProject(str) {
        this.showLoading(true, '');
        let data: any = {
            BuMenBH: this.branchId,
            NianDu: this.year,
            YongHuBH: this.userId,
            ZhiBiaoMC: str,
            DanJuBH:this.danJuBH,
            BaoXiaoLX:this.bxType
        };
        this.sys.getProject(data).subscribe((res: any) => {
            if (res.msgCode == '1') {
                this.planList =res.list;
                if(this.planList.length==0){
                    this.showError('你搜索的指标不存在');
                }
            } else {
                this.showError('系统错误')
            }
            this.showLoading(false, '')

        }, error => {
            this.showError('网络连接错误');
            this.showLoading(false, '')

        })
    }
    close(){

        //this.change.emit(this.isShow);
        if(this.view){
            this.view.dismiss(null, '', {animate: false});

        }

    }

}
